/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2013
 */

package com.smg.community.dao;

import java.util.*;

import javacommon.base.*;
import javacommon.util.*;

import cn.org.rapid_framework.util.*;
import cn.org.rapid_framework.web.util.*;
import cn.org.rapid_framework.page.*;
import cn.org.rapid_framework.page.impl.*;

import com.smg.community.model.*;
import com.smg.community.dao.*;
import com.smg.community.service.*;
import com.smg.community.vo.query.*;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */


import org.springframework.stereotype.Repository;


@Repository
public class SmgMemberDao extends BaseIbatis3Dao<SmgMember,java.lang.Integer>{
	
	@Override
	public String getIbatisMapperNamesapce() {
		return "SmgMember";
	}
	
	public void saveOrUpdate(SmgMember entity) {
		if(entity.getMemberId() == null) 
			save(entity);
		else 
			update(entity);
	}
	
	public Page findPage(SmgMemberQuery query) {
		return pageQuery("SmgMember.findPage",query);
	}

	public SmgMember getByLoginNameAndPassword(String loginName, String password) {
		Map<String,String> map = new HashMap<String,String>();
		map.put("password",password);
		map.put("loginName",loginName);
		return (SmgMember)this.getSqlSessionTemplate().selectOne("SmgMember.getByLoginNameAndPassword", map);
	}

	public void addTopicCount(int memberId) {
			this.getSqlSessionTemplate().update("SmgMember.addTopicCount", memberId);
	}

	public void addPoint(int type, int point, String detail, SmgMember member) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("detail",detail);
		map.put("point",point);
		map.put("type",type);
		map.put("fkMemberId",member.getMemberId());
		map.put("nickName",member.getNickName());
		map.put("createDate",new Date());
		this.getSqlSessionTemplate().update("SmgMember.addPoint", map);
	}

	public List<SmgMember> getThreeMemberByBehaviorCount() {
		return (List<SmgMember>)this.getSqlSessionTemplate().selectList("SmgMember.getThreeMemerByBehaviorCount", null);
	}

	public List<SmgMember> getTopXMemberList(int size) {
		return (List<SmgMember>)this.getSqlSessionTemplate().selectList("SmgMember.getTopXMemberList", size);
	}

	public List<SmgMember> getFourStaffMember() {
		return  (List<SmgMember>)this.getSqlSessionTemplate().selectList("SmgMember.getFourStaffMember",null);
	}

	public List<SmgMember> getFourFriendMember(Integer memberId) {
		return  (List<SmgMember>)this.getSqlSessionTemplate().selectList("SmgMember.getFourFriendMember", memberId);
	}

	public void	 addVisitCount(int viewMemberId) {
		this.getSqlSessionTemplate().update("SmgMember.addVisitCount", viewMemberId);
	}

	public List<SmgMember> getFocusMemberByMemberId(Integer memberId, int size) {
		Map map = new HashMap();
		map.put("memberId",memberId);
		map.put("limit",size);
		return  (List<SmgMember>)this.getSqlSessionTemplate().selectList("SmgMember.getFocusMemberByMemberId", map);
	}

	public void updateHead(Integer memberId, String headImage) {
		Map map = new HashMap();
		map.put("memberId",memberId);
		map.put("headImage",headImage);
		this.getSqlSessionTemplate().update("SmgMember.updateHead", map);
	}

	public SmgMember getByNickname(String nickName) {
		return (SmgMember)this.getSqlSessionTemplate().selectOne("SmgMember.getByNickname", nickName);
	}

	public void updatePassword(Integer memberId, String newpassword) {
		Map map = new HashMap();
		map.put("memberId",memberId);
		map.put("newpassword",newpassword);
		this.getSqlSessionTemplate().update("SmgMember.updatePassword", map);
	}

	public List<SmgMember> getFourLastedJoinGroupMember(Integer groupId) {
		return	this.getSqlSessionTemplate().selectList("SmgMember.getFourLastedJoinGroupMember", groupId);
	}

	public SmgMember getStarMemberInOneWeek() {
		return  (SmgMember)this.getSqlSessionTemplate().selectOne("SmgMember.getStarMemberInOneWeek",null);
	}

	public void addFocusAndFansCount(int fromMemberId, int focusMemberId) {
		Map map = new HashMap();
		map.put("fromMemberId",fromMemberId);
		map.put("focusMemberId",focusMemberId);
		this.getSqlSessionTemplate().update("SmgMember.addFocusAndFansCount", map);
	}

	public void subFocusAndFansCount(Integer fromMemberId, int focusMemberId) {
		// TODO Auto-generated method stub
		Map map = new HashMap();
		map.put("fromMemberId",fromMemberId);
		map.put("focusMemberId",focusMemberId);
		this.getSqlSessionTemplate().update("SmgMember.subFocusAndFansCount", map);
	}

	public void subPoint(Integer memberId, int point) {
		
		Map map = new HashMap();
		map.put("memberId",memberId);
		map.put("point",point);
		this.getSqlSessionTemplate().update("SmgMember.subPoint", map);
	}

	public SmgMember getByLoginName(String loginName) {
		return (SmgMember)getSqlSessionTemplate().selectOne("SmgMember.getByLoginName", loginName);
	}

	public void updateNickname(Integer memberId, String nickName) {
		Map map = new HashMap();
		map.put("memberId",memberId);
		map.put("nickName",nickName);
		this.getSqlSessionTemplate().update("SmgMember.updateNickname", map);
	}
	

}
